unit Class_GKJL_IN_GKZF;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TGKJL=class(TUniEngine)
  private
    FUNITLINK: string;
    FGKJGIDEX: Integer;
    FGKJLIDEX: Integer;
    FGKJLMEMO: string;
    FGKJLLOAD: Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property UNITLINK: string read FUNITLINK write FUNITLINK;
    property GKJGIDEX: Integer read FGKJGIDEX write FGKJGIDEX;
    property GKJLIDEX: Integer read FGKJLIDEX write FGKJLIDEX;
    property GKJLMEMO: string read FGKJLMEMO write FGKJLMEMO;
    property GKJLLOAD: Integer read FGKJLLOAD write FGKJLLOAD;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AGKJL:TGKJL):TGKJL;overload;        
    class procedure CopyIt(AGKJL:TGKJL;var Result:TGKJL);overload;       
  end;

implementation

{ TGKJL }
procedure TGKJL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GKJG_IDEX').Value := GKJGIDEX;
        ParamByName('GKJL_IDEX').Value := GKJLIDEX;
        ParamByName('GKJL_MEMO').Value := GKJLMEMO;
        ParamByName('GKJL_LOAD').Value := GKJLLOAD; 
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GKJG_IDEX').Value := GKJGIDEX;
        ParamByName('GKJL_IDEX').Value := GKJLIDEX;
        ParamByName('GKJL_MEMO').Value := GKJLMEMO;
        ParamByName('GKJL_LOAD').Value := GKJLLOAD; 
      end;  
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GKJG_IDEX').Value := GKJGIDEX;
        ParamByName('GKJL_IDEX').Value := GKJLIDEX;
 
      end;  
    end;
  end;
end;

function TGKJL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('GKX_GKJL',['UNIT_LINK',UNITLINK,'GKJG_IDEX',GKJGIDEX,'GKJL_IDEX',GKJLIDEX],AUniConnection);
end;

function TGKJL.GetNextIdex: Integer;
begin

end;

function TGKJL.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TGKJL.GetStrDelete: string;
begin
  Result:='DELETE FROM GKX_GKJL WHERE   UNIT_LINK=:UNIT_LINK AND GKJG_IDEX=:GKJG_IDEX AND GKJL_IDEX=:GKJL_IDEX';
end;

function TGKJL.GetStrInsert: string;
begin
  Result:='INSERT INTO GKX_GKJL'
         +'    ( UNIT_LINK, GKJG_IDEX, GKJL_IDEX, GKJL_MEMO, GKJL_LOAD)'
         +'    VALUES'
         +'    (:UNIT_LINK,:GKJG_IDEX,:GKJL_IDEX,:GKJL_MEMO,:GKJL_LOAD)';
end;

function TGKJL.GetStrsIndex: string;
begin
  Result:=Format('%S-%D-%D',[UNITLINK,GKJGIDEX,GKJLIDEX]);
end;

function TGKJL.GetStrUpdate: string;
begin
  Result:='UPDATE  GKX_GKJL SET'
         +'    GKJL_MEMO=:GKJL_MEMO,'
         +'    GKJL_LOAD=:GKJL_LOAD'
         +'    WHERE UNIT_LINK=:UNIT_LINK'
         +'    AND   GKJG_IDEX=:GKJG_IDEX'
         +'    AND   GKJL_IDEX=:GKJL_IDEX';
end;

constructor TGKJL.Create;
begin
  UNITLINK:='-1';
  GKJGIDEX:=1;
  GKJLIDEX:=1;
  GKJLMEMO:='<GKJLMEMO>';
  GKJLLOAD:=0;
end;

destructor TGKJL.Destroy;
begin

  inherited;
end;

class function TGKJL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TGKJL.Create;
  with TGKJL(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    GKJGIDEX:=AUniQuery.FieldByName('GKJG_IDEX').AsInteger;
    GKJLIDEX:=AUniQuery.FieldByName('GKJL_IDEX').AsInteger;
    GKJLMEMO:=AUniQuery.FieldByName('GKJL_MEMO').AsString;
    GKJLLOAD:=AUniQuery.FieldByName('GKJL_LOAD').AsInteger;
  end;  
end;

class procedure TGKJL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TGKJL(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    GKJGIDEX:=AUniQuery.FieldByName('GKJG_IDEX').AsInteger;
    GKJLIDEX:=AUniQuery.FieldByName('GKJL_IDEX').AsInteger;
    GKJLMEMO:=AUniQuery.FieldByName('GKJL_MEMO').AsString;
    GKJLLOAD:=AUniQuery.FieldByName('GKJL_LOAD').AsInteger;
  end;  
end;

class function  TGKJL.CopyIt(AGKJL: TGKJL): TGKJL;
begin
  Result:=TGKJL.Create;
  TGKJL.CopyIt(AGKJL,Result)
end;

class procedure TGKJL.CopyIt(AGKJL:TGKJL;var Result:TGKJL);
begin
  if Result=nil then Exit;
  Result.UNITLINK:=AGKJL.UNITLINK;
  Result.GKJGIDEX:=AGKJL.GKJGIDEX;
  Result.GKJLIDEX:=AGKJL.GKJLIDEX;
  Result.GKJLMEMO:=AGKJL.GKJLMEMO;
  Result.GKJLLOAD:=AGKJL.GKJLLOAD;
end;

end.

